home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / AIAT 1.0.1 / Headers / Accessor / RankedQuery.h < prev    next >
Encoding:
Text File  |  1997-09-11  |  4.6 KB  |  174 lines  |  [TEXT/CWIE]

  1. // RankedQuery.h
  2. //    Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  3. // Utility for preparing queries for ranked search -- used by both vector & inverted accessors.
  4. // Not directly used by client code, but rather by accessor implementations.
  5.  
  6. #pragma once
  7. #ifndef RankedQuery_h
  8. #define RankedQuery_h
  9.  
  10. #pragma import on
  11.  
  12. #include "RankedAccessor.h"
  13. #include "Similarity.h"
  14. #include "Progress.h"
  15. #include "SkipList.h"
  16.  
  17. #pragma IA_BEGIN_EXPORTS
  18.  
  19. //// RankedQuery: a term-indexed skip list of <term, termInfo+, scaleFactor, queryWeight> entries
  20. struct RQEntry : public IAStruct {
  21.                     RQEntry() : infos(NULL), term(NULL), weight(0.0) {}
  22.     IATerm*            term;                    // the term (pointer into the first info)
  23.     TermInfo**        infos;                    // array of TermInfos -- one per index
  24.     float            scaleFactor;            // for weighting vectors
  25.     float            weight;                    // this term's weight in the query
  26. };
  27.  
  28. class TFMap;
  29. class StringDocText;
  30.  
  31. class IAQuery : public SkipList {            // a skip list of RQEntry's ordered by term
  32. public:
  33.         IAQuery() : nIndices(0), SkipList(sizeof(RQEntry)) {}
  34.         virtual ~IAQuery();
  35.  
  36.     // All the work is done by Initialize() -- would be ctor, but need return value.
  37.     // Returns true iff the query analysis was aborted.
  38.     virtual bool        Initialize();
  39.     
  40.     virtual IADocText*    GetQueryText() = 0;
  41.     virtual uint32         GetNumberOfQueryDocs() = 0;
  42.     virtual RankedQueryDoc* GetQueryDocs() = 0;
  43.     void     SetIndicies (TermIndex** indicies, uint32 numberofindicies);
  44.     uint32     GetNumberOfIndicies() {return nIndices;}
  45.                              
  46.     bool            Remove(RQEntry* rqe);
  47.     RQEntry*        First() { return (RQEntry*)SkipList::First(); }
  48.     RQEntry*        Next(RQEntry* rqe) { return (RQEntry*)SkipList::Next(rqe); }
  49.     virtual bool    ComputeTermScaleFactors();
  50.     
  51.     void SetSimilarity (Similarity* similarity) {sim = similarity;}
  52.     void SetProgress    (Progress* p) {progress = p;}
  53.     Similarity* GetSimilarity () {return sim;}
  54.     Progress* GetProgress (){return progress;}
  55.  
  56. protected:
  57.  
  58.     bool            LessThanInline(SkipNode n, SkipNode m);
  59.     bool            LessThan(const SkipNode n, const SkipNode m);
  60.     bool            Equal(const SkipNode n, const SkipNode m);
  61.     virtual SkipNode SetFinger(const SkipNode k, SL_Finger f);
  62.  
  63.     void            AddTerms(TFMap* tfMap);
  64.     bool            ComputeDocTFMaps(RankedQueryDoc* docQuery, uint32 nDocs, TFMap** tfMaps);
  65.     void            WeightTFMap(TFMap* tfMap);
  66.     void            SumWeights(TFMap** maps, uint32 nMaps);
  67.     void            SetWeight(IATerm* term, float weight);
  68. private:
  69.     TermIndex**        indices;
  70.     uint32            nIndices;
  71.     Similarity*        sim;
  72.     Progress*        progress;
  73.  
  74. };
  75.  
  76. class IARankedQuery : public IAQuery {            
  77. public:
  78.         IARankedQuery(): fTextQuery(NULL), fTextQueryLength(0), 
  79.                          fDocQuery(NULL), fNumberOfDocs(0), fStringText(NULL){}
  80.         IARankedQuery(byte*     textQuery,    uint32     textQueryLen,
  81.                     RankedQueryDoc*    docQuery,     uint32     nDocs);
  82.  
  83.         virtual ~IARankedQuery();
  84.         
  85.         void SetTextQuery(byte* textQuery,    uint32     textQueryLen);
  86.         void SetQueryDoc(RankedQueryDoc*    docQuery,     uint32     nDocs);
  87.         
  88.         virtual IADocText*    GetQueryText();
  89.         virtual uint32         GetNumberOfQueryDocs();
  90.         virtual RankedQueryDoc* GetQueryDocs();
  91.             
  92. private:
  93.     byte*            fTextQuery;
  94.     uint32            fTextQueryLength;
  95.     RankedQueryDoc*    fDocQuery;
  96.     uint32             fNumberOfDocs;
  97.     StringDocText*    fStringText;
  98. };
  99.  
  100. class IADocTextQuery : public IAQuery {            
  101. public:
  102.         IADocTextQuery () : fTextQueryDoc(NULL), fDocQuery(NULL), fNumberOfDocs(0){}
  103.         IADocTextQuery (IADocText*     textQueryDoc,
  104.                     RankedQueryDoc*    docQuery,     uint32     nDocs);
  105.  
  106.         virtual ~IADocTextQuery();
  107.         
  108.         void SetDocTextQuery (IADocText* textQueryDoc);
  109.         void SetQueryDoc (RankedQueryDoc*    docQuery,     uint32     nDocs);
  110.  
  111.         virtual IADocText*    GetQueryText();
  112.         virtual uint32         GetNumberOfQueryDocs();
  113.         virtual RankedQueryDoc* GetQueryDocs();
  114.             
  115. private:
  116.     IADocText*         fTextQueryDoc;
  117.     RankedQueryDoc*    fDocQuery;
  118.     uint32             fNumberOfDocs;
  119. };
  120.  
  121. inline void IAQuery::SetIndicies (TermIndex** inds, uint32 numberofindicies)
  122. {
  123.     indices = inds;
  124.     nIndices = numberofindicies;
  125. }
  126.  
  127. inline void IARankedQuery::SetQueryDoc (RankedQueryDoc*    docQuery,     uint32     nDocs)
  128. {
  129.     fDocQuery = docQuery;
  130.     fNumberOfDocs = nDocs;
  131. }
  132.  
  133.  
  134. inline uint32 IARankedQuery::GetNumberOfQueryDocs()
  135. {
  136.     return fNumberOfDocs;
  137. }
  138.  
  139. inline RankedQueryDoc* IARankedQuery::GetQueryDocs() 
  140. {
  141.     return fDocQuery;
  142. }
  143.  
  144. inline IADocText* IARankedQuery::GetQueryText()
  145. {
  146.     return (IADocText*)fStringText;
  147. }
  148.  
  149. inline void IADocTextQuery::SetDocTextQuery(IADocText* textQueryDoc)
  150. {
  151.     fTextQueryDoc = textQueryDoc;
  152. }
  153.  
  154. inline void IADocTextQuery::SetQueryDoc (RankedQueryDoc*    docQuery,     uint32     nDocs)
  155. {
  156.     fDocQuery = docQuery;
  157.     fNumberOfDocs = nDocs;
  158. }
  159.  
  160. inline uint32 IADocTextQuery::GetNumberOfQueryDocs() 
  161. {
  162.     return fNumberOfDocs;
  163. }
  164.  
  165. inline RankedQueryDoc* IADocTextQuery::GetQueryDocs()
  166. {
  167.     return fDocQuery;
  168. }
  169.  
  170. #pragma IA_END_EXPORTS
  171.  
  172. #pragma import reset
  173. #endif
  174.